from fastapi import APIRouter, Depends, Request

from forward.api.h5.schemas.lucky.activity import (
    ActivityCheckDrawEligibleInSchema,
    ActivityDetailInSchema,
    ActivityDrawNumInSchema,
    ActivityListInSchema,
)
from forward.api.h5.service.lucky.activity import ActivityService
from forward.dependencies.verify import h5_admin_verify

activity = APIRouter(prefix="/activity")


@activity.post("/detail")
async def detail(
    detail_in: ActivityDetailInSchema,
    activity_service: ActivityService = Depends(),
):
    activity_id = detail_in.activity_id
    return await activity_service.detail(activity_id)


@activity.post("/user_draw_info")
async def user_draw_info(
    request: Request,
    detail_in: ActivityDetailInSchema,
    activity_service: ActivityService = Depends(),
):
    """
    获取用户抽奖信息
    """
    user_id = request.state.user_id
    return await activity_service.get_user_draw_info(
        activity_id=detail_in.activity_id, user_id=user_id, code_=detail_in.code
    )


@activity.post("/draw_num")
async def get_draw_num(
    request: Request,
    draw_num_in: ActivityDrawNumInSchema,
    activity_service: ActivityService = Depends(),
):
    user_id = request.state.user_id
    return await activity_service.get_draw_num(
        user_id=user_id, activity_id=draw_num_in.activity_id, code_=draw_num_in.code
    )


@activity.post("/check_draw_eligible")
async def check_draw_eligible(
    request: Request,
    check_draw_eligible_in: ActivityCheckDrawEligibleInSchema,
    activity_service: ActivityService = Depends(),
):
    user_id = request.state.user_id
    return await activity_service.check_draw_eligible(
        user_id=user_id,
        activity_id=check_draw_eligible_in.activity_id,
        code=check_draw_eligible_in.code,
    )


@activity.post("/lists", dependencies=[Depends(h5_admin_verify)])
async def list(
    list_in: ActivityListInSchema, activity_service: ActivityService = Depends()
):
    return await activity_service.lists(list_in)
